#include "HaarLikeDetector.h"

using namespace std;
using namespace cv;

int HaarLikeDetector::detectObjects(vector<Rect>& outDetectedObjects, vector<double>& outConfidences, Mat& inFrame)
{
	if(mClassifier.empty() || inFrame.empty())	//NULL pointer(s)
		return -1;
	if(mXFlip)
	{
		cv::flip(inFrame, inFrame, 1); //XFlip ?????
	}

	//vector<double> lLevelWeights;
	//vector<int> lRejectLevels;
	//mClassifier.detectMultiScale(inFrame,outDetectedObjects,lRejectLevels,lLevelWeights,mScaleFactor,mMinNeighbors,mFlags,mMinSize,cv::Size(),true);
	mClassifier.detectMultiScale(inFrame,outDetectedObjects,mScaleFactor,mMinNeighbors,mFlags,mMinSize,mMaxSize);

	int lNbObjects = outDetectedObjects.size();
	if(lNbObjects>0)
	{
		for(unsigned int i = 0; i < outDetectedObjects.size(); i++ )
		{
			//TODO::Check here
			//outConfidences[i]=mAPrioriConfidence*lLevelWeights[i];
			outConfidences.push_back(mAPrioriConfidence);
			if(mXFlip)
				outDetectedObjects[i].x = inFrame.cols - (outDetectedObjects[i].x+outDetectedObjects[i].width);
		}
	}

	if(mXFlip)
	{
		cv::flip(inFrame, inFrame, 1); //XFlip ?????
	}
	return lNbObjects;
}

bool HaarLikeDetector::readClassifier(std::string inPath)
{
	return mClassifier.load(inPath);
}